home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Science / Gnuplot 3.5 / docs / doc2info.pl < prev    next >
Perl Script  |  1993-11-03  |  3KB  |  128 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # doc2texinfo : Converts Gnuplot .doc files to Texinfo format.
  4. #
  5. # George Ferguson, ferguson@cs.rochester.edu, 11 Feb 1991.
  6. #
  7. # Usage:
  8. #    % doc2texinfo gnuplot.doc >gnuplot.texinfo
  9. #    % makeinfo +fill-column 80 gnuplot.texinfo
  10. # Creates files "gnuplot.info" and "gnuplot.info-[123]".
  11. #
  12.  
  13. $currentBook = $currentChapter = $currentSection = $currentSubsection = 0;
  14. $verbatim = $table = 0;
  15.  
  16. while (<>) {
  17.     if (/^([1-4]) (.*)$/) {    # section heading
  18.     $table = 0;
  19.     &endVerbatim;
  20.     $numNodes += 1;
  21.     $nodeLevel[$numNodes] = $1;
  22.     $nodeTitle[$numNodes] = $2;
  23.     $nodeText[$numNodes] = "";
  24.     if ($1 == 1) {
  25.         $currentBook = $numNodes;
  26.     } elsif ($1 == 2) {
  27.         $currentChapter = $numNodes;
  28.         $nodeMenu[$currentBook] .= "* $2::\n";
  29.     } elsif ($1 == 3) {
  30.         $currentSection = $numNodes;
  31.         if ($nodeTitle[$currentChapter] eq "set-show") {
  32.         $nodeTitle[$numNodes] = "set $2";    # override
  33.         $nodeMenu[$currentChapter] .= "* set $2::\n";
  34.         } else {
  35.         $nodeMenu[$currentChapter] .= "* $2::\n";
  36.         }
  37.     } elsif ($1 == 4) {
  38.         $currentSubsection = $numNodes;
  39.         $nodeMenu[$currentSection] .= "* $2::\n";
  40.     }
  41.     } elsif (/^\?(.*)$/) {                # index entry
  42.     if ($1 ne "") {
  43.         $nodeText[$numNodes] .= "\@cindex $1\n";
  44.     }
  45.     } elsif (/^@start table/) {                # start table
  46.     &startVerbatim;
  47.     $table = 1;
  48.     } elsif (/^@end table/) {                # end table
  49.     $table = 0;
  50.     &endVerbatim;
  51.     } elsif (/^#/ || /^%/) {                # table entry
  52.     next;
  53.     } elsif (/^ ( ?)(.*)$/) {                # text
  54.     if ($1 eq " ") {
  55.         &startVerbatim;
  56.     } else {
  57.         &endVerbatim;
  58.     }
  59.     $text = $2;
  60.     $text =~ s/@/@@/g;
  61.     $text =~ s/{/\@{/g;
  62.     $text =~ s/}/\@}/g;
  63.      $text =~ s/\`([^`]*)\`/@code{$1}/g;
  64.     $nodeText[$numNodes] .= "$text\n";
  65.     } elsif (/^$/) {                    # blank line
  66.     &endVerbatim;
  67.     $nodeText[$numNodes] .= "\n";
  68.     }
  69. }
  70.  
  71. # Print texinfo header
  72. print "\\input texinfo\n";
  73. print "@setfilename gnuplot.info\n";
  74. print "@settitle Gnuplot: An Interactive Plotting Program\n";
  75. print "\n";
  76. print "@node Top\n";
  77. print "@top Gnuplot";
  78. print "\n";
  79. print "$nodeText[1]";
  80. print "\@menu\n";
  81. print "$nodeMenu[1]";
  82. print "* General Index::\n";
  83. print "\@end menu\n";
  84. print "\n";
  85.  
  86. # Now output all the nodes
  87. for ($i=2; $i <= $numNodes; $i++) {
  88.     print "\@node $nodeTitle[$i]\n";
  89.     if ($nodeLevel[$i] == 2) {
  90.     print "\@chapter $nodeTitle[$i]\n";
  91.     } elsif ($nodeLevel[$i] == 3) {
  92.     print "\@section $nodeTitle[$i]\n";
  93.     } elsif ($nodeLevel[$i] == 4) {
  94.     print "\@subsection $nodeTitle[$i]\n";
  95.     }
  96.     print "$nodeText[$i]";
  97.     if ($nodeMenu[$i] ne "") {
  98.     print "\@menu\n";
  99.     print $nodeMenu[$i];
  100.     print "\@end menu\n";
  101.     }
  102.     print "\n";
  103. }
  104. # Print texinfo trailer
  105. print "\n";
  106. print "@node General Index\n";
  107. print "@appendix General Index\n";
  108. print "\n";
  109. print "@printindex cp\n";
  110. print "\n";
  111. print "@bye\n";
  112.  
  113. #######################
  114.  
  115. sub startVerbatim {
  116.     if (!$verbatim) {
  117.     $nodeText[$numNodes] .= "\@example\n";
  118.     $verbatim = 1;
  119.     }
  120. }
  121.  
  122. sub endVerbatim {
  123.     if ($verbatim && !$table) {
  124.     $nodeText[$numNodes] .= "\@end example\n";
  125.     $verbatim = 0;
  126.     }
  127. }
  128.